#! /usr/bin/env python
# encoding: utf-8
# Ricard Marxer 2008

import os, sys

def options(opt):
    opt.load('compiler_cxx')
    opt.load('python')

def configure(conf):
    conf.load('compiler_cxx python')
    conf.check_python_version((2,4,2))
    conf.check_python_headers()
    
    conf.check_cfg(package='fftw3 fftw3f fftw3l', uselib_store='FFTW3', errmsg='FFTW not found. No FFT support.')
    conf.check_cfg(package='samplerate', uselib_store='SAMPLERATE', mandatory=True)
    conf.check_cfg(package='eigen3', uselib_store='EIGEN', mandatory=True)

    conf.load('swig')
    if conf.check_swig_version() < (1, 2, 27):
        conf.fatal('this swig version is too old')

    conf.check_python_module('numpy')
    conf.load('numpy')

    import numpy
    conf.env.append_value('CXXFLAGS', ['-I' + numpy.get_include()])
    

def build(bld):
    bld(features = 'cxx cxxshlib pyext',
        uselib = 'FFTW3 FFMPEG SAMPLERATE EIGEN',
        source = 'loudia.i',
        target = '_loudia',
        swig_flags = '-c++ -python -Wall -w509 -I..',
        includes = '.. /usr/include/eigen3',
        name         = 'pyloudia',
        want_libtool = 1,
        vnum         = '1.0.0',
        use = 'loudia'
        )
    
    bld.env['PYTHONDIR'] = os.path.join(bld.env['PYTHONDIR'], 'loudia')
    bld.install_as('${PYTHONDIR}/__init__.py', 'loudia.py')
    
